#!/usr/bin/env python
# -*- coding: utf-8 -*-

def fr(a, b=None):
    if b is None:
        return a
    else:
        return float(a) / float(b)


# Uncomment the following line to use fractions

# from fractions import Fraction as fr


def cal_p(m, n):
    P = [fr(0)] * (m - n + 1)
    for M in range(m - n + 1, m + 1):
        P2 = [0] * (M + 1)
        half = (M + 1) // 2
        P.append(fr(0))
        for i in range(1, M + 1):
            if i % 2 == 0:
                P2[i] = fr(i // 2, half) * P[i - 1] + fr(half - i // 2, half) * P[i]
            else:
                P2[i] = fr(1, half) + fr(i // 2, half) * P[i - 1] + fr(half - i // 2 - 1, half) * P[i]
        P = P2
    return P


import matplotlib.pyplot as plt


def plot_q(M, N):
    P = cal_p(M, N)
    q = [1.0 - p for p in P[1:]]
    plt.figure()
    plt.plot(q)
    plt.show()


if __name__ == '__main__':
    plot_q(600, 598)